package com.woniuxy.qimenggateway.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class RequestUtil {
    /**
     * 从Cookie中返回数据
     * @param name
     * @param request
     * @return
     */
    public static String getCookie(String name, HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        if(cookies != null && cookies.length != 0){
            for (Cookie c:cookies) {
                if(c.getName().equals(name)) return c.getValue();
            }
        }

        return null;
    }

    /**
     * 从请求头中返回数据
     * @param name
     * @param request
     * @return
     */
    public static String getHeader(String name, HttpServletRequest request){
        return request.getHeader(name);
    }

}
